package org.maitaole.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.maitaole.entity.TbCategoryBrand;
import org.maitaole.mapper.TbCategoryBrandMapper;
import org.maitaole.service.ITbCategoryBrandService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class TbCategoryBrandServiceImpl implements ITbCategoryBrandService {

    @Resource
    private TbCategoryBrandMapper tbCategoryBrandMapper;

    /**
     * 根据类别id查询品牌id
     * @param categoryId 传入的商品类别id
     * @return 品牌id的list集合
     */
    @Override
    public List<Integer> getBrandIdByCategoryId(Integer categoryId) {
        List<Integer> fkBrandIds = new ArrayList<>();
        QueryWrapper<TbCategoryBrand> tbCategoryBrandQueryWrapper = new QueryWrapper<>();
        tbCategoryBrandQueryWrapper.eq("fk_category_id",categoryId);
        List<TbCategoryBrand> tbCategoryBrands = tbCategoryBrandMapper.selectList(tbCategoryBrandQueryWrapper);
        for (TbCategoryBrand tbCategoryBrand : tbCategoryBrands) {
            fkBrandIds.add(tbCategoryBrand.getFkBrandId());
        }
        return fkBrandIds;
    }
}
